package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.RegionDao;
import com.x.erp.model.Region;
import com.x.erp.rpc.RegionRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Service(interfaceName = "com.x.erp.rpc.RegionRpcService", timeout = 60000)
public class RegionService extends BaseService implements RegionRpcService {

	@Autowired
	private RegionDao regionDao;

	@Override
	public List<Region> selectRegionList(Region region) {
		try {
			return regionDao.selectRegionList(region);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectRegionNum(Region region) {
		try {
			return regionDao.selectRegionNum(region);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public Region insertRegion(Region region) {
		try {
			region.setRegionCreateTime(this.getDate(0));
			return this.insert(region);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void updateRegion(Region region) {
		try {
			this.update(region);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
